new Vue({
  el: '#app',
  data() {
    return {
      shop: false,
      form: {
        App_ID: "",
        token: $.cookie("token"),
        page: 1,			//页数
        limit: 10			//每页数据条数
      },
      total: 0,//总条数
      options: [],//小程序appid
      value: '',
      formData: {},
      tableData: [{}],		//表格数据
      dialogForm: false,
      title: '',
      Benefits: [],
      row: '',
      Member_Type_SerialNumber: '',
      MemberBenefits: [],
      loading: false,
      dialogVisible: false,
      formLabelWidth: '120px'
    }
  },
  mounted() {
    this.getList(this.form)
    this.getData()
  },
  methods: {
    onSerach() {				//查询方法
      this.getList(this.form)
    },
    addContract() {
      console.log("跳转")
    },
    getData() { //获取选择器里的数据
      let _this = this
      $.ajax({
        type: 'POST',
        url: DomainName + '/getInquiryAction',
        data: {
          Data: "enterprise_appid",
          token: $.cookie("token")
        },
        success: function (Result) {
          _this.options = Result
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("Contentpath");
          }
        },
        dataType: "json"
      });
    },
    getList(data) {     //换页方法
      let _this = this
      $.ajax({
        type: 'POST',
        url: DomainName + '/getMemberInfoAction',
        data,
        success: function (Result) {
          _this.tableData = Result.tableData;
          _this.total = parseInt(Result.limit)
          console.log(_this.tableData)
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("Contentpath");
          }
        },
        dataType: "json"
      });
    },
    // 添加员工
    showMember(row, Type) {
      const _this = this
      _this.loading = true
      let member_type_journal = {
        Member_Type_SerialNumber: '',
        Employee_Authority: Type,
        Appoint_Member_Type: row.Appoint_Member_Type,
        Member_Rights_SerialNumber: row.Member_Rights_SerialNumber
      }
      let detel = {};
      $.ajax({
        url: DomainName + '/getInquiryIDOriginal',
        type: 'POST',
        data: {
          Primary_Key_Name: 'Member_SerialNumber',
          Data: 'member_info',
          Primary_Key: row.Member_SerialNumber,
          token: $.cookie("token")
        },
        success: function (res) {
          console.log(res)
          if (res.length == 1) {
            res[0].Employee_Authority = Type
            detel = res[0];
            let data = {
              Data: JSON.stringify({ Modify: { member_info: [detel] }, Add: { member_type_journal: [member_type_journal] } }),
              token: $.cookie("token")
            };
            $.ajax({
              url: DomainName + '/getEditAction',
              type: 'POST',
              data,
              success: function (res) {
                if (res.Status === 'success') {
                  _this.$message.success("更改成功");
                  _this.getList(_this.form);
                } else {
                  _this.$message.error("操作失败，请稍后再试")
                }
              },
              error: function () {
                _this.$message.error("操作失败，请稍后再试")
              },
              complete: function (XMLHttpRequest) {
                _this.loading = false
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("Contentpath");
                }
              },
            })
          }
        }
      })
    },
    // 晋升会员
    PromotedMembership(row) {
      let _this = this
      _this.row = row
      $.ajax({
        type: 'POST',
        url: DomainName + '/getMemberRightsAppIDAction',
        data: {
          Enterprise_Info_SerialNumber: $.cookie("enterprise"),
          token: $.cookie("token"),
          App_ID: row.App_ID
        },
        success: function (res) {
          if (res.Status === 'success') {

            _this.Benefits = res.Data
            console.log(_this.Benefits)
          } else if (res.Cause) {
            console.log(res.Cause)
          } else {
            _this.$message.error("提交失败")
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
      this.dialogVisible = true
    },
    // 确认升级
    UpgradeMembership() {
      let _this = this
      _this.loading = true
      let member_type_journal = {
        Member_Type_SerialNumber: '',
        Employee_Authority: _this.row.Employee_Authority,
        Appoint_Member_Type: '1',
        Member_Rights_SerialNumber: _this.row.Member_Rights_SerialNumber,
        Open_ID: _this.row.Open_ID,
        Member_SerialNumber: _this.row.Member_SerialNumber
      }
      console.log(_this.row)
      console.log(member_type_journal)
      let detel = {};
      $.ajax({
        url: DomainName + '/getInquiryIDOriginal',
        type: 'POST',
        data: {
          Primary_Key_Name: 'Member_SerialNumber',
          Data: 'member_info',
          Primary_Key: _this.row.Member_SerialNumber,
          token: $.cookie("token")
        },
        success: function (res) {
          console.log(res)
          if (res.length == 1) {
            res[0].Appoint_Member_Type = '1'
            res[0].Member_Rights_SerialNumber = _this.Member_Type_SerialNumber
            detel = res[0];
            let data = {
              Data: JSON.stringify({ Modify: { member_info: [detel] }, Add: { member_type_journal: [member_type_journal] } }),
              token: $.cookie("token")
            };
            $.ajax({
              url: DomainName + '/getEditAction',
              type: 'POST',
              data,
              success: function (res) {
                if (res.Status === 'success') {
                  _this.$message.success("更改成功");
                  _this.getList(_this.form);
                } else {
                  _this.$message.error("操作失败，请稍后再试")
                }
              },
              error: function () {
                _this.$message.error("操作失败，请稍后再试")
              },
              complete: function (XMLHttpRequest) {
                _this.loading = false
                _this.dialogVisible = false
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("Contentpath");
                }
              },
            })
          }
        }
      })
    },
    // 清空弹出框
    CloseBenefits() {
      this.Member_Type_SerialNumber = []
    },
    RelationshipDiagram() {
      window.location.href = './show.html'
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
  },
})